package com.hongdee.crm.question.controller;

import com.hongdee.common.util.EntityUtils;
import com.hongdee.crm.question.entity.TCrmSurveryQuestionGroup;
import com.hongdee.crm.question.service.ITCrmQuestionGroupService;
import com.hongdee.crm.question.service.Impl.TCrmQuestionGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Name: 问卷管理 问题项管理
 * @Author: Liu XiaoLong
 * @Date: 2017/10/15 11:52
 * @Remark:
 */

@RestController
@RequestMapping("/crm/question/group")
public class TCrmQuestionGroupController {
    @Autowired
    private ITCrmQuestionGroupService itCrmQuestionGroupService;

    /**
     * @Name: 前端提交的问题树保存
     * @Author: Liu XiaoLong
     * @Date: 2017/10/17 20:35
     * @Remark:
     */
    @RequestMapping("/save")
    public Map saveOrUpdate(@RequestParam(name = "uid",value = "") String uid,
                            @RequestParam(name = "token",value = "") String token,
                            @RequestBody Map data) throws Exception{
        Map map = new HashMap();
        TCrmSurveryQuestionGroup rel = itCrmQuestionGroupService.saveOrUpdate(uid,data);
        map.put("data",rel);
        map.put("success",true);
        map.put("msg","保存成功");
        return map;
    }

    /**
     * @Name: 获取左侧树
     * @Author: Liu XiaoLong
     * @Date: 2017/10/16 09:57
     * @Remark:
     */
    @RequestMapping("/leftTree")
    public Map getLeftTree(@RequestParam(name = "uid",value = "") String uid,
                           @RequestParam(name = "token",value = "") String token,
                           @RequestParam(name = "questionId",value = "") String questionId,
                           @RequestBody Map data)throws  Exception{
        Map map = itCrmQuestionGroupService.getLeftTree(uid,questionId,data);
        map.put("success",true);
        map.put("msg","查询成功");

        return map;
    }


    @RequestMapping("/questionData")
    public Map questionData(@RequestParam(name = "uid",defaultValue = "") String uid,
                            @RequestParam(name = "token",defaultValue = "") String token,
                            @RequestParam(name = "questionId",defaultValue = "") String questionId) throws Exception{


         Map map = itCrmQuestionGroupService.questionData(uid,questionId);
        map.put("success",true);
        map.put("msg","查询成功");
        return map;
    }

}
